<?php
if ( count($data->records) != 0 ) {
$hojas = ceil(count($data->records) / 8);
$j = 0;
$m = 0;
for ( $k = 1; $k <= $hojas; $k++ ) { ?>
    <table class="" style="page-break-after: always;">
        <?php for(; $j < 8*$k; $j++ ) {
            if (isset($data->records[$j]['certs']) && count($data->records[$j]['certs']) != 0) {
                $user = $data->records[$j]['certs'];
                if ($j % 2 == 0) {?>
                    <tr>
                <?php } ?>
                <td class="passport" style=''>
                    <div class="headPasport">
                        <div>
                            <?php echo $this->Html->image('bosch-logo.png', array('height' => '30px')); ?>
                        </div>
                        <div>
                            <p><?php echo $data->records[$j]['str']['title']; ?></p>
                        </div>
                        <div class="iconCategorization">
                            <i class="<?php echo $data->records[$j]['catIcon']; ?>" style="color: <?php echo $data->records[$j]['catColor']; ?> !important; @media print { color: <?php echo $data->records[$j]['catColor']; ?> !important; }"></i>
                        </div>
                    </div>
                    <div class="bodyPassport" >
                        <div>
                            <div class="mla">
                                <?php echo $data->records[$j]['nameLine']; ?>
                            </div>
                            <div class="numNom">
                                <?php echo $user[0]['numNom']; ?>
                            </div>
                        </div>
                        <div class="nomAsc">
                            <?php echo $user[0]['nameAsc']; ?>
                        </div>
                        <div class="tablaCert">
                            <?php if (count($user) > 15 ) { ?>
                            <table style="width: 50%">
                                <?php } else { ?>
                                <table style="width: 100%">
                                    <?php } ?>
                                    <?php
                                    $i = 0;
                                    if (isset($user[$i])) {
                                        for( ; $i < 15; $i++) {
                                            if (isset($user[$i])) { ?>
                                                <tr>
                                                    <td>
                                                        <p class="nameWork" ><?php echo $user[$i]['nameWork']; ?></p>
                                                    </td>
                                                    <td>
                                                        <?php if($user[$i]['sucss'] == '1') { ?>
                                                            <i class="fa fa-check-circle sucss"></i>
                                                        <?php } elseif ($user[$i]['train'] == '1') { ?>
                                                            <i class="fa fa-flag train"></i>
                                                        <?php } ?>
                                                    </td>
                                                    <td>
                                                        <?php if($user[$i]['sucss'] == '1') { ?>
                                                            <p class="fechaCert"><?php echo $user[$i]['life']; ?></p>
                                                        <?php } elseif ($user[$i]['train'] == '1') { ?>
                                                            <p class="fechaFinCert"><?php echo $user[$i]['end']; ?></p>
                                                        <?php } ?>
                                                    </td>
                                                </tr>
                                            <?php } else { ?>
                                                <tr>
                                                    <td>&nbsp;</td>
                                                    <td>&nbsp;</td>
                                                    <td>&nbsp;</td>
                                                </tr>
                                            <?php }
                                        }
                                    }
                                    ?>
                                </table>
                                <table>
                                    <?php
                                    if (isset($user[$i])) {
                                        for( ; $i < 30; $i++) {
                                            if (isset($user[$i])) { ?>
                                                <tr>
                                                    <td>
                                                        <p class="nameWork" ><?php echo $user[$i]['nameWork']; ?></p>
                                                    </td>
                                                    <td>
                                                        <?php if($user[$i]['sucss'] == '1') { ?>
                                                            <i class="fa fa-check-circle sucss"></i>
                                                        <?php } elseif ($user[$i]['train'] == '1') { ?>
                                                            <i class="fa fa-flag train"></i>
                                                        <?php } ?>
                                                    </td>
                                                    <td>
                                                        <?php if($user[$i]['sucss'] == '1') { ?>
                                                            <p class="fechaCert"><?php echo $user[$i]['life']; ?></p>
                                                        <?php } elseif ($user[$i]['train'] == '1') { ?>
                                                            <p class="fechaFinCert"><?php echo $user[$i]['end']; ?></p>
                                                        <?php } ?>
                                                    </td>
                                                </tr>
                                            <?php } else { ?>
                                                <tr>
                                                    <td>&nbsp;</td>
                                                    <td>&nbsp;</td>
                                                    <td>&nbsp;</td>
                                                </tr>
                                            <?php }
                                        }
                                    }
                                    ?>
                                </table>
                        </div>
                    </div>
                </td>
                <?php if ($j % 2 != 0) {?>
                    </tr>
                <?php }
            }
        } ?>
    </table>
<?php }
} else { ?>
    <div class="alert alert-warning">No encontraron certificaciones</div>
<?php } ?>